import { nextTick } from 'vue'
import { createRouter, createWebHashHistory, RouteRecordRaw, RouteLocationNormalized, NavigationGuardNext} from 'vue-router'
import NotFound from '../views/404.vue'



const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: () => import('../views/blank/blankPage.vue')
    // redirect: '/doctorToday'
  },
  {
    path: '/doctorToday',
    name: 'DoctorToday',
    component: () => import('../views/myWork/doctorToday.vue'),
    meta: {title: '今日就诊'}
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home.vue'),
    meta: { title: "首页", icon: "el-icon-s-home" },
  },
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
	{
    path: '/test',
    name: 'Test',
    component: () => import(/* webpackChunkName: "about" */ '../views/Test.vue')
  },
  // 我的工作(医生)
  {
    path: '/doctorWork',
    name: 'DoctorWork',
    component: () => import('../views/myWork/doctorWork.vue'),
    meta: {title: '我的工作'}
  },
  // 我的工作(前台)
  {
    path: '/doctorToday',
    name: 'DoctorToday',
    component: () => import('../views/myWork/doctorToday.vue'),
    meta: {title: '今日就诊'}
  },
  {
    path: '/waitingCharge',
    name: 'WaitingCharge',
    component: () => import('../views/myWork/waitingCharge.vue'),
    meta: {title: '待收费'}
  },
  {
    path: '/charged',
    name: 'Charged',
    component: () => import('../views/myWork/charged.vue'),
    meta: {title: '已收费'}
  },
  {
    path: '/appointmentCancel',
    name: 'AppointmentCancel',
    component: () => import('../views/myWork/appointmentCancel.vue'),
    meta: {title: '预约已取消'}
  },
  {
    path: '/returnVisitToday',
    name: 'ReturnVisitToday',
    component: () => import('../views/myWork/returnVisitToday.vue'),
    meta: {title: '今日回访'}
  },
  {
    path: '/followUpToday',
    name: 'FollowUpToday',
    component: () => import('../views/myWork/followUpToday.vue'),
    meta: {title: '今日随访'}
  },
  {
    path: '/appointmentTomorrow',
    name: 'AppointmentTomorrow',
    component: () => import('../views/myWork/appointmentTomorrow.vue'),
    meta: {title: '明日预约'}
  },
  {
    path: '/birthdayTips',
    name: 'BirthdayTips',
    component: () => import('../views/myWork/birthdayTips.vue'),
    meta: {title: '生日提醒'}
  },
  {
    path: '/bePending',
    name: 'BePending',
    component: () => import('../views/myWork/BePending.vue'),
    meta: {title: '待定预约'}
  },


  // 预约中心模块
  {
    path: '/appointment',
    name: 'AppointmentWork',
    component: () => import('../views/appointment/appointment.vue'),
    meta: {title: '预约中心'}
  },

  // 患者中心模块
  {
    path: '/allPatients',
    name: 'AllPatients',
    component: () => import('../views/patients/allPatients.vue'),
    meta: {title: '全部患者'}
  },
  {
    path: '/allPatientDetails/:id',
    name: 'AllPatientDetails',
    component: () => import('../views/patients/allPatientDetails.vue'),
    meta: {title: '全部患者详情'},
    children: [
      {
        path:'patient',
        name: 'Patient',
        component: () => import('../views/patients/details/patient.vue'),
        meta: {title: '患者信息'},
      },
      {
        path:'record',
        name: 'Record',
        component: () => import('../views/patients/details/record.vue'),
        meta: {title: '就诊记录'},
      },
      {
        path:'member',
        name: 'Member',
        component: () => import('../views/patients/details/member.vue'),
        meta: {title: '会员信息'},
      },
      {
        path:'priceSet',
        name: 'PriceSet',
        component: () => import('../views/patients/details/priceSet.vue'),
        meta: {title: '划价'},
      },
      {
        path:'chargeModel',
        name: 'ChargeModel',
        component: () => import('../views/patients/details/chargeModel.vue'),
        meta: {title: '收费'},
      },
      {
        path:'medicalRecord',
        name: 'MedicalRecord',
        component: () => import('../views/patients/details/medicalRecord.vue'),
        meta: {title: '电子病历'},
      },
      {
        path:'image',
        name: 'Image',
        component: () => import('../views/patients/details/image.vue'),
        meta: {title: '影像'},
      },
      {
        path:'followUp',
        name: 'FollowUp',
        component: () => import('../views/patients/details/followup.vue'),
        meta: {title: '随访'},
      },
      {
        path:'returnvisit',
        name: 'Returnvisit',
        component: () => import('../views/patients/details/returnvisit.vue'),
        meta: {title: '回访'},
      },
      {
        path:'machin',
        name: 'Machin',
        component: () => import('../views/patients/details/machining.vue'),
        meta: {title: '计加工'},
      }
    ]
  },
  {
    path: '/myPatients',
    name: 'MyPatients',
    component: () => import('../views/patients/myPatients.vue'),
    meta: {title: '我的患者'}
  },
  {
    path: '/followUpManagement',
    name: 'FollowUpManagements',
    component: () => import('../views/patients/followUpManagement.vue'),
    meta: {title: '随访管理'}
  },
  {
    path: '/returnvisitManagement',
    name: 'ReturnVisitManagement',
    component: () => import('../views/patients/returnvisitManagement.vue'),
    meta: {title: '回访管理'}
  },

  // 报表中心
  {
    path: '/appointmentAnalysis',
    name: 'AppointmentAnalysis',
    component: () => import('../views/report/appointmentAnalysis.vue'),
    meta: {title: '预约分析'}
  },
  {
    path: '/references',
    name: 'References',
    component: () => import('../views/report/references.vue'),
    meta: {title: '推荐人分析'}
  },
  {
    path: '/patientVisits',
    name: 'PatientVisits',
    component: () => import('../views/report/patientVisits.vue'),
    meta: {title: '患者就诊分析'}
  },
  {
    path: '/reconciliationCalendar',
    name: 'ReconciliationCalendar',
    component: () => import('../views/report/reconciliationCalendar.vue'),
    meta: {title: '对账日历'}
  },
  {
    path: '/dailyReconciliation',
    name: 'DailyReconciliation',
    component: () => import('../views/report/dailyReconciliation.vue'),
    meta: {title: '每日对账'}
  },
  {
    path: '/incomeSummary',
    name: 'IncomeSummary',
    component: () => import('../views/report/incomeSummary.vue'),
    meta: {title: '收入汇总'}
  },
  {
    path: '/cashFlow',
    name: 'CashFlow',
    component: () => import('../views/report/cashFlow.vue'),
    meta: {title: '现金流'}
  },
  {
    path: '/billDetails',
    name: 'BillDetails',
    component: () => import('../views/report/billDetails.vue'),
    meta: {title: '账单明细'}
  },
  {
    path: '/projectDetails',
    name: 'ProjectDetails',
    component: () => import('../views/report/projectDetails.vue'),
    meta: {title: '项目明细'}
  },
  {
    path: '/patientsInArrears',
    name: 'PatientsInArrears',
    component: () => import('../views/report/patientsInArrears.vue'),
    meta: {title: '欠费患者'}
  },
  {
    path: '/refundList',
    name: 'RefundList',
    component: () => import('../views/report/refundList.vue'),
    meta: {title: '退费列表'}
  },

  // 进销存


  {
    path: '/manage',
    name: 'Manage',
    component: () => import('../views/warehouse/manage.vue'),
    meta: {title: "仓库管理"}
  },
  {
    path: '/stockInOrder',
    name: 'StockInOrder',
    component: () => import('../views/warehouse/stockInOrder.vue'),
    meta: {title: "入库单"}
  },
  {
    path: '/stockOrderDetails',
    name: 'StockOrderDetails',
    component: () => import('../views/warehouse/stockOrderDetails.vue'),
    meta: {title: "入库单详情"}
  },
  {
    path: '/delivery',
    name: 'Delivery',
    component: () => import('../views/warehouse/delivery.vue'),
    meta: {title: "出库管理"}
  },
  {
    path: '/deliveryDetails',
    name: 'DeliveryDetails',
    component: () => import('../views/warehouse/deliveryDetails.vue'),
    meta: {title: "出库管理详情"}
  },
  {
    path: '/allocation',
    name: 'Allocation',
    component: () => import('../views/warehouse/allocation.vue'),
    meta: {title: "调拨管理"}
  },
  {
    path: '/allocationDetails',
    name: 'AllocationDetails',
    component: () => import('../views/warehouse/allocationDetails.vue'),
    meta: {title: "调拨管理详情"}
  },
  {
    path:'/lossStatement',
    name: 'LossStatement',
    component: () => import('../views/warehouse/lossStatement.vue'),
    meta: {title:'损益单'}
  },
  {
    path:'/lossStatementDetails',
    name: 'LossStatementDetails',
    component: () => import('../views/warehouse/lossStatementDetails.vue'),
    meta: {title:'损益单详情'}
  },
  {
    path: '/inventory',
    name: 'Inventory',
    component: () => import('../views/warehouse/inventory.vue'),
    meta: {title: "盘点管理"}
  },
  {
    path: '/goods',
    name: 'Goods',
    component: () => import('../views/warehouse/goods.vue'),
    meta: {title: "物品管理"}
  },
  {
    path: '/supplier',
    name: 'Supplier',
    component: () => import('../views/warehouse/supplier.vue'),
    meta: {title: "供应商管理"}
  },
  {
    path: '/inventoryReport',
    name: 'InventoryReport',
    component: () => import('../views/warehouse/inventoryReport.vue'),
    meta: {title: "进销存报表"}
  },


  // 技加工 模块
  {
    path: '/skillPlusMerit',
    name: 'SkillPlusMerit',
    component: () => import('../views/skill/skillPlusMerit.vue'),
    meta: {title: "技加工"}
  },





  // 系统设置
  {
    path: '/coupon',
    name: 'Coupon',
    component: () => import('../views/system/coupon/coupon.vue'),
    meta: { title: "优惠券"},
  },
  {
    path: '/projectPreference',
    name: 'ProjectPreference',
    component: () => import('../views/system/projectPreference/projectPreference.vue'),
    meta: { title: "项目优惠"},
  },
  {
    path: '/orderDiscount',
    name: 'OrderDiscount',
    component: () => import('../views/system/orderDiscount/orderDiscount.vue'),
    meta: { title: "订单优惠"},
  },
  {
    path: '/payService',
    name: 'PayService',
    component: () => import('../views/system/payService/payService.vue'),
    meta: { title: "收费项目"},
  },
  // {
  //   path: '/sys/company',
  //   name: 'Company',
  //   component: () => import('../views/system/company.vue'),
  //   meta: { title: "公司管理"},
  // },
  // {
  //   path: '/menus',
  //   name: 'Menus',
  //   component: () => import('../views/system/menu/menu.vue'),
  //   meta: { title: "菜单管理"},
  // },
  {
    path: '/role',
    name: 'Role',
    component: () => import('../views/system/role/role.vue'),
    meta: { title: "角色管理"},
  },
  {
    path: '/user',
    name: 'User',
    component: () => import('../views/system/user/user.vue'),
    meta: { title: "用户管理"},
  },
  // {
  //   path: '/branch',
  //   name: 'Branch',
  //   component: () => import('../views/system/branch/branch.vue'),
  //   meta: { title: "分院管理"},
  // },
  // {
  //   path: '/userBranch',
  //   name: 'UserBranch',
  //   component: () => import('../views/system/userBranch/userBranch.vue'),
  //   meta: { title: "用户部门"},
  // },
  {
    path: '/sms/smsType',
    name: 'SmSType',
    component: () => import('../views/system/sms/index.vue'),
    meta: { title: "短信管理"},
  },
  {
    path: '/visit/followUpManagement',
    name: 'FollowUpManagement',
    component: () => import('../views/system/visit/followUpManagement.vue'),
    meta: { title: "随访管理"},
  },
  {
    path: '/config/selectedConfigAll',
    name: 'SelectedConfigAll',
    component: () => import('../views/system/config/selectedConfigAll.vue'),
    meta: { title: "下拉配置"},
  },






  {
    path: '/:pathMatch(.*)*',
    redirect: '/404'
  },
  {
    path: '/404',
    name: 'Error',
    component: NotFound
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to: RouteLocationNormalized,from: RouteLocationNormalized, next: NavigationGuardNext) => {
  console.log(to, from)
  let token = window.localStorage.getItem('TOKEN') || ''
  if(to.fullPath != '/' && token) {
    window.localStorage.setItem('currentPath', to.fullPath)
  }
  next()
})



export default router
